package only.my.railgunys.utils;

import only.my.railgunys.artifact.*;
import only.my.railgunys.artifact.calc.SubStatRollCalc;
import only.my.railgunys.bean.Character;
import only.my.railgunys.bean.db.Artifact;
import only.my.railgunys.bean.db.PossibleFinalForm;

import java.util.*;
import java.util.stream.Collectors;

import static java.util.Arrays.asList;

public class ArtifactSetUtils {

    static List<MainStatRoll> sandsOfEonMainStatList = asList(
            new MainStatRoll("沙漏 ",ArtifactSetUtils::attackEffective,ArtifactSetUtils::attackMainStat),
            new MainStatRoll("沙漏 ",ArtifactSetUtils::rechargeEffective,ArtifactSetUtils::rechargeMainStat),
            new MainStatRoll("沙漏 ",ArtifactSetUtils::masteryEffective,ArtifactSetUtils::masteryMainStat),
            new MainStatRoll("沙漏 ",ArtifactSetUtils::hpEffective,ArtifactSetUtils::hpMainStat),
            new MainStatRoll("沙漏 ",ArtifactSetUtils::defenseEffective,ArtifactSetUtils::defenseMainStat));
    static List<MainStatRoll> cupMainStatList = asList(
            new MainStatRoll("杯 ",ArtifactSetUtils::attackEffective,ArtifactSetUtils::attackMainStat),
            new MainStatRoll("杯 ",ArtifactSetUtils::masteryEffective,ArtifactSetUtils::masteryMainStat),
            new MainStatRoll("杯 ",ArtifactSetUtils::defenseEffective,ArtifactSetUtils::defenseMainStat),
            new MainStatRoll("杯 ",ArtifactSetUtils::hpEffective,ArtifactSetUtils::hpMainStat),
            new MainStatRoll("杯 ",ArtifactSetUtils::elementDmgEffective,ArtifactSetUtils::elementDmgMainStat),
            new MainStatRoll("杯 ",ArtifactSetUtils::physicalDmgEffective,ArtifactSetUtils::physicalDmgMainStat)
            );
    static List<MainStatRoll> circletMainStatList = asList(
            new MainStatRoll("头",ArtifactSetUtils::attackEffective,ArtifactSetUtils::attackMainStat),
            new MainStatRoll("头",ArtifactSetUtils::masteryEffective,ArtifactSetUtils::masteryMainStat),
            new MainStatRoll("头",ArtifactSetUtils::defenseEffective,ArtifactSetUtils::defenseMainStat),
            new MainStatRoll("头",ArtifactSetUtils::hpEffective,ArtifactSetUtils::hpMainStat),
            new MainStatRoll("头",ArtifactSetUtils::critDmgEffective,ArtifactSetUtils::critDmgMainStat),
            new MainStatRoll("头",ArtifactSetUtils::critRateEffective,ArtifactSetUtils::critRateMainStat),
            new MainStatRoll("头",ArtifactSetUtils::healingBonusEffective,ArtifactSetUtils::healingBonusMainStat)
    );

    public static List<Character> mainStatRollEnhance(Character character){

        character.addHp(4870D);
        character.setAtk_ex(character.getAtk_ex()+311D);
        List<Character> collect_sands = sandsOfEonMainStatList.stream()
                .map(mainStatRoll -> mainStatRoll.enhanceCharacter(character, ArtifactSetUtils::sandMainType))
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
        List<Character> characters_cups = cupMainStatList.stream()
                .map(mainStatRoll -> collect_sands.stream().map(character1 -> mainStatRoll.enhanceCharacter(character1, ArtifactSetUtils::cupMainType))
                        .filter(Objects::nonNull)
                        .collect(Collectors.toList()))
                .flatMap(Collection::stream)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());

        return circletMainStatList.stream()
                .map(mainStatRoll -> characters_cups.stream()
                        .map(character1 -> mainStatRoll.enhanceCharacter(character1, ArtifactSetUtils::circletMainType))
                        .filter(Objects::nonNull)
                        .collect(Collectors.toList()))
                .flatMap(Collection::stream)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
    }
    public static List<Character> possibleStatRollEnhance(List<Character> characterList , int effectiveNumber){
        List<Character> characterAfterSubArtifact = new ArrayList<>();
        for (int i = 0; i <= effectiveNumber; i++) {
            for (int j = effectiveNumber-i; j >= 0; j--) {
                EffectiveSubStatRoll essr = new EffectiveSubStatRoll(i,j,effectiveNumber-i-j);
                List<Character> collectTemp = characterList.stream().map(essr::enhanceCharacter).collect(Collectors.toList());
                characterAfterSubArtifact.addAll(collectTemp);
            }
        }
        return characterAfterSubArtifact;
    }
    public static List<Character> possibleStatRollEnhance3(List<Character> characterList , int effectiveNumber){
        List<Character> characterAfterSubArtifact = new ArrayList<>();
        for (int i = 0; i <= effectiveNumber; i++) {
            for (int j = effectiveNumber-i; j >= 0; j--) {
                for (int k = 0; k < effectiveNumber - i-j; k++) {
                    EffectiveSubStatRoll essr = new EffectiveSubStatRoll(i,j,k,effectiveNumber-i-j-k);
                    List<Character> collectTemp = characterList.stream().map(essr::enhanceCharacter).collect(Collectors.toList());
                    characterAfterSubArtifact.addAll(collectTemp);
                }
            }
        }
        return characterAfterSubArtifact;
    }

    public static List<Character> possibleStatRollEnhance4(List<Character> characterList , int effectiveNumber){
        List<Character> characterAfterSubArtifact = new ArrayList<>();
        for (int i = 0; i <= effectiveNumber; i++) {
            for (int j = effectiveNumber-i; j >= 0; j--) {
                for (int k = 0; k < effectiveNumber - i-j; k++) {
                    for (int l = 0; l < effectiveNumber - i - j - k; l++) {
                        EffectiveSubStatRoll essr = new EffectiveSubStatRoll(i,j,k,l,effectiveNumber-i-j-k-l);
                        List<Character> collectTemp = characterList.stream().map(essr::enhanceCharacter).collect(Collectors.toList());
                        characterAfterSubArtifact.addAll(collectTemp);
                    }
                }
            }
        }
        return characterAfterSubArtifact;
    }

    public static void attackMainStat(Character character, MainArtifactStatType mainType){
        character.addAtk(46.6);
        character.addDescription("攻击");
        mainType.artifactType(character,1);
    }
    public static void sandMainType(Character character,int type){
        character.setSandType(type);
    }
    public static void cupMainType(Character character,int type){
        character.setCupType(type);
    }
    public static void circletMainType(Character character,int type){
        character.setCirclet(type);
    }
    public static boolean attackEffective(Character character){
        return character.isAtkUseful();
    }
    public static void rechargeMainStat(Character character, MainArtifactStatType mainType){
        character.addRecharge(51.8);
        character.addDescription("充能");
        mainType.artifactType(character,2);
    }
    public static boolean rechargeEffective(Character character){
        return character.isRechargeUseful();
    }
    public static void hpMainStat(Character character, MainArtifactStatType mainType){
        character.addHp(character.getHp()*0.466);
        character.addDescription("生命");
        mainType.artifactType(character,3);
    }
    public static boolean hpEffective(Character character){
        return character.isHpUseful();
    }
    public static void masteryMainStat(Character character, MainArtifactStatType mainType){
        character.addMastery(187);
        character.addDescription("精通");
        mainType.artifactType(character,4);
    }
    public static boolean masteryEffective(Character character){
        return character.isMasteryUseful();
    }
    public static void defenseMainStat(Character character, MainArtifactStatType mainType){
        character.addDefense(58.3);
        character.addDescription("防御");
        mainType.artifactType(character,5);
    }
    public static boolean defenseEffective(Character character){
        return character.isDefenseUseful();
    }
    public static void elementDmgMainStat(Character character, MainArtifactStatType mainType){
        character.addIncrease(46.6);
        character.addDescription("属伤");
        mainType.artifactType(character,6);
    }
    public static boolean elementDmgEffective(Character character){
        return character.isElementDmgUseful();
    }
    public static void physicalDmgMainStat(Character character, MainArtifactStatType mainType){
        character.addIncrease(58.3);
        character.addDescription("物伤");
        mainType.artifactType(character,7);
    }
    public static boolean physicalDmgEffective(Character character){
        return character.isPhysicalDmgUseful();
    }
    public static void critDmgMainStat(Character character, MainArtifactStatType mainType){
        character.addCritDmg(62.2);
        character.addDescription("爆伤");
        mainType.artifactType(character,8);
    }
    public static boolean critDmgEffective(Character character){
        return character.isCritRateUseful();
    }
    public static void critRateMainStat(Character character, MainArtifactStatType mainType){
        character.addCritRate(31.1);
        character.addDescription("暴击率");
        mainType.artifactType(character,9);
    }
    public static boolean critRateEffective(Character character){
        return character.isCritRateUseful();
    }
    public static void healingBonusMainStat(Character character, MainArtifactStatType mainType){
        character.addHealingBonus(35.9);
        character.addDescription("治疗");
        mainType.artifactType(character,0);
    }
    public static boolean healingBonusEffective(Character character){
        return character.isHealingBonusUseful();
    }


}
